xquery version "1.0";

import module namespace layout="http://www.example.com/layout" at "xmldb:exist:///db/projdb/modules/layout.xqm";
import module namespace request="http://exist-db.org/xquery/request";

declare option exist:serialize "doctype-public=-//W3C//DTD&#160;XHTML&#160;1.1//EN
                                doctype-system=http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";



declare function local:getSingleLabelsMannen( $amount ) as element()
{
    let $singleLabels := subsequence( document('/db/projdb/clusterdataMostPopular.xml')/result/singleLabels/mannen/label, 1, $amount )
    
    return element ol {
        for $label in $singleLabels
            return element li {
                data($label/name)," (",data($label/occurences),")"
            }
    }
};

declare function local:getSingleLabelsVrouwen( $amount ) as element()
{
    let $singleLabels := subsequence( document('/db/projdb/clusterdataMostPopular.xml')/result/singleLabels/vrouwen/label, 1, $amount )
    
    return element ol {
        for $label in $singleLabels
            return element li {
                data($label/name)," (",data($label/occurences),")"
            }
    }
};
declare variable $summ {document('/db/projdb/onderbrekerstotalen.xml')/onderbrekerstotalen};
declare variable $aantal {sum($summ/entry/aantal)};
declare variable $names {document('/db/projdb/lijst_van_sprekers_ge2009.xml')/speakers/speaker};
declare variable $aantalm  {count($names[./sex = 'M'])};
declare variable $aantalv {count($names[./sex = 'F'])};
declare variable $aantalmo {count($summ/entry[./geslacht = 'M'])};
declare variable $aantalvo {count($summ/entry[./geslacht = 'F'])};
declare variable $onderbrekingsTovTotaalMannen{ round-half-to-even(sum($summ/entry[./geslacht = 'M']/aantal) div $aantalm,2)};
declare variable $onderbrekingsTovTotaalVrouwen{round-half-to-even(sum($summ/entry[./geslacht = 'F']/aantal) div $aantalv,2)};
declare variable $onderbrekingsTovTotaalGraf {<img src="http://chart.apis.google.com/chart?chxt=y&amp;chbh=a&amp;chs=700x250&amp;cht=bvg&amp;chco=000080|800000&amp;chd=t:{$onderbrekingsTovTotaalMannen},{$onderbrekingsTovTotaalVrouwen}&amp;chbh=a,200,200&amp;chl=Mannen|Vrouwen" />};



declare variable $onderbrekingsTovEigenMannen{round-half-to-even(100 *$aantalmo div $aantalm,2)};
declare variable $onderbrekingsTovEigenVrouwen{round-half-to-even(100 *$aantalvo div $aantalv,2)};
declare variable $onderbrekingsTovEigenGraf{<img src="http://chart.apis.google.com/chart?chxt=y&amp;chbh=a&amp;chs=700x250&amp;cht=bvg&amp;chco=000080|800000&amp;chd=t:{concat(concat(round-half-to-even(100 *$aantalmo div $aantalm,2),','),round-half-to-even(100 *$aantalvo div $aantalv,2))}&amp;chbh=a,200,200&amp;chl=Mannen|Vrouwen" />};

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Activiteit in de plenaire vergaderingen</title>
        <link rel="stylesheet" style="text/css" href="style/core_layout.css"/>
		<script type="text/javascript" src="js/jquery.js"><!-- --></script>
        <script type="text/javascript" src="https://www.google.com/jsapi"><!-- --></script>
        <script type="text/javascript" src="js/activity.js"><!-- --></script>
        <script type="text/javascript" src="js/myScripts.js"><!-- --></script>
        <script type="text/javascript">
            //<![CDATA[
            google.load("visualization", "1", {packages:["corechart"]});
            google.setOnLoadCallback(function() {
                initShowHideButtons();

                activity_setUpdateFunction(function(xml) {
                    activity_loadManWomenRankingChart(xml, "manWomenRankingChartContainer", 700, 400);
                    activity_loadManWomenQuartilePieChart(xml, "manWomenQuartileChartContainerMan", 'M', true);
                    activity_loadManWomenQuartilePieChart(xml, "manWomenQuartileChartContainerWomen", 'F', true);
                    
                    activity_loadQuartileManWomenPieChart(xml, 'manWomenRankingPieChartFirstPartContainer', 'firstPart', 'Kwartiel 1 (top)');
                    activity_loadQuartileManWomenPieChart(xml, 'manWomenRankingPieChartSecondPartContainer', 'secondPart', 'Kwartiel 2');
                    activity_loadQuartileManWomenPieChart(xml, 'manWomenRankingPieChartThirdPartContainer', 'thirdPart', 'Kwartiel 3');
                    activity_loadQuartileManWomenPieChart(xml, 'manWomenRankingPieChartFourthPartContainer', 'fourthPart', 'Kwartiel 4');
                    });

                activity_run();
            });
            //]]>
        </script>
        
        
    </head>
    <body>	
          <div class="containerBox">
          {layout:topMenu()}
  
        <div class="box" id="titleBox">
            <div class="margin">
                <h1>Mannen vs Vrouwen</h1>
            </div>
        </div>

        <div class="box" id="manWomenActivityChartBox">
            <div class="margin">
                <h2 class="boxTitle">Activeitsranking</h2>
                <div class="boxContent">
                    <div id="manWomenRankingChartContainer">
                        <!-- Auto generated -->
                    </div>
                </div>
            </div>
        </div>

        <div class="box" id="manWomenRankingPieChartBox">
            <div class="margin">
                <h2 class="boxTitle">Kwartielen</h2>
                <div class="boxContent columnContent">
                    <div class="columnspace twoColumns">
                        <div class="column" id="manWomenRankingPieChartFirstPartContainer" style="height:250px;"><!-- Auto generated --></div>
                        <div class="column" id="manWomenRankingPieChartSecondPartContainer" style="height:250px;"><!-- Auto generated --></div>
                        <br class="clearer" />
                    </div>
                    <div class="columnspace twoColumns">
                        <div class="column" id="manWomenRankingPieChartThirdPartContainer" style="height:250px;"><!-- Auto generated --></div>
                        <div class="column" id="manWomenRankingPieChartFourthPartContainer" style="height:250px;"><!-- Auto generated --></div>
                        <br class="clearer" />
                    </div>
                </div>
            </div>
        </div>

        <div class="box" id="manWomenQuartileChartBox">
            <div class="margin">
                <h2 class="boxTitle">Kwartielen per geslacht</h2>
                <div class="boxContent columnContent">
                    <div class="columnspace twoColumns">
                        <div class="column" id="manWomenQuartileChartContainerMan" style="height:250px;"><!-- Auto generated --></div>
                        <div class="column" id="manWomenQuartileChartContainerWomen" style="height:250px;"><!-- Auto generated --></div>

                        <br class="clearer" />
                    </div>
                </div>
            </div>
        </div>


        
        <div class="box" id="mostPopularSingleLabelSubjectsManAndFemale">
            <div class="margin">
                <h2 class="boxTitle">Meest populaire onderwerpen<span class="button"></span></h2>
                <div class="boxDescription">
                    <p>In de linkse kolom worden de 10 meestvoorkomende labels, uit alle clusters tesamen, getoond die minstens 1 maal werden gebruikt door mannen. In de rechtse kolom wordt hetzelfde gedaan, maar dan voor vrouwen. Het getal achter ieder label geeft duid aan door hoeveel mannen/vrouwen het label werd gebruikt.</p>
                </div>
                <div class="boxContent darkBackground">
                    <div class="columnspace twoColumns darkBackground">
                        <div class="column activityChart firstColumn">
                            <h3 class="columnTitle">Mannen</h3>
                            { local:getSingleLabelsMannen( 10 ) }
                        </div>
                        <div class="column activityChart secondColumn">
                            <h3 class="columnTitle">Vrouwen</h3>
                            { local:getSingleLabelsVrouwen( 10 ) }
                        </div>
                        <br class="clearer"/>
                    </div>
                </div>
            </div>
        </div>
       
        <div class="box" id="onderbrekingsTovTotaalBox">
            <div class="margin">
                <h2 class="boxTitle">Onderbrekingen per geslacht t.o.v. het totaal</h2>
                                <div class="boxDescription">
                <p>Hier wordt weergegeven hoeveel mannen/vrouwen gemiddeld onderbreken.</p>
                </div>
                <div class="boxContent darkBackground">
                    <div class="columnspace twoColumns darkBackground">
                        <div class="column firstColumn">
                            <h3 class="columnTitle">Mannen</h3>
                            <ul><li>{$onderbrekingsTovTotaalMannen}</li></ul>
                            </div>
                        <div class="column secondColumn">
                            <h3 class="columnTitle">Vrouwen</h3>
                              <ul><li>{$onderbrekingsTovTotaalVrouwen}</li></ul>
                        </div>
                    <br class="clearer"/>
                    </div>
                </div> 
           
                <div class="boxContent" style="margin-top:10px">
                        {$onderbrekingsTovTotaalGraf }
                </div>
              </div>
          </div>
          
          
          <div class="box" id="onderbrekingsTovEigenBox">
            <div class="margin">
                <h2 class="boxTitle">Onderbrekingen per geslacht t.o.v. het eigen geslacht</h2>
                                <div class="boxDescription">
                <p>Hier wordt weergegeven hoeveel (in percentage) van de mannen/vrouwen er ooit onderbroken heeft.</p>
                </div>
                <div class="boxContent darkBackground">
                    <div class="columnspace twoColumns darkBackground">
                        <div class="column firstColumn">
                            <h3 class="columnTitle">Mannen</h3>
                            <ul><li>{$onderbrekingsTovEigenMannen}</li></ul>
                            </div>
                        <div class="column secondColumn">
                            <h3 class="columnTitle">Vrouwen</h3>
                              <ul><li>{$onderbrekingsTovEigenVrouwen}</li></ul>
                        </div>
                    <br class="clearer"/>
                    </div>
                </div> 
           
                <div class="boxContent" style="margin-top:10px">
                        {$onderbrekingsTovEigenGraf }
                </div>
              </div>
          </div>
        </div>
    </body>
</html>
